package com.zhixing.service.executor;

import com.zhixing.model.SwaggerDefinitionModelAttr;
import com.zhixing.service.parse.SwaggerDefinitionsDefinitionsParser;
import com.zhixing.service.parse.SwaggerJsonStrDefinitionsParser;
import com.zhixing.service.parse.SwaggerPathParser;

import java.io.IOException;
import java.util.Map;

/**
 * 通用 swagger 2 word 执行器
 * @author zhixing
 */
public class SimpleSwagger2WordExecutor  extends AbstractSwagger2WordExecutor {

    public SimpleSwagger2WordExecutor(String swaggerJsonStr) {
        super(swaggerJsonStr);
        // 进行 json 处理得到结果集
        executor();
    }

    @Override
    protected void doProcessSwaggerJsonStr() throws IOException {

        // 解析 swagger json str
        Map<String, Object> allMapResult = SwaggerJsonStrDefinitionsParser.createBuild()
                .swaggerJsonStr(this.swaggerJsonStr)
                .build()
                .parse()
                .getAllMapResult();

        //解析model
        Map<String, SwaggerDefinitionModelAttr> definitionMap = SwaggerDefinitionsDefinitionsParser.createBuild()
                .allMap(allMapResult)
                .build()
                .parse()
                .getSwaggerModelAttrMapResult();

        //解析paths
        this.setApiResultList(
                SwaggerPathParser.createBuild()
                        .allMap(allMapResult)
                        .definitinMap(definitionMap)
                        .build()
                        .parse()
                        .getResultTableList()
        );

        this.setAllResultMap(allMapResult);
    }
}
